<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>如何返回介于 x（包括）与 y（不包括）之间的随机整数</title>
</head>

<body>
    <h2>JavaScript Math.random()</h2>
    <p>每当您点击按钮，getRndInteger(min, max) 就会返回 0 与 9（均包含）之间的随机数：</p>
    <button onclick="document.getElementById('demo').innerHTML = getRndInteger(0,10)">点击我</button>
    <p id="demo"></p>
    <script>
        function getRndInteger(min, max) {
            return Math.floor(Math.random() * (max - min)) + min;
        }
    </script>
</body>

</html>